package com.eds.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.eds.common.utils.PageUtils;
import com.eds.common.utils.R;
import com.eds.mall.product.vo.SpuInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.eds.mall.product.entity.SpuInfoEntity;
import com.eds.mall.product.service.SpuInfoService;


/**
 * spu信息
 *
 * @author zz
 * @email zhouzhen@qq.com
 * @date 2024-04-03 16:00:43
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;


    /**
     * /product/spuinfo/6/up
     *  商品上架功能
     *  我们需要根据 spuid查询出需要储存的商品
     *  存储到 ElasticSearch 中，并修改 spu数据中的上架状态
     * @param spuId
     * @return
     */
    @PostMapping("/{id}/up")
    public R spuUp(@PathVariable("id") Long spuId) {
        spuInfoService.up(spuId);
        return R.ok("上传成功");
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = spuInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:spuinfo:info")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:spuinfo:save")
    public R save(@RequestBody SpuInfoVO spuInfo){
		// spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:spuinfo:update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:spuinfo:delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
